package cn.stylefeng.guns.modular.education.controller;

import cn.stylefeng.roses.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;

import org.springframework.ui.Model;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;

import cn.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import cn.stylefeng.guns.modular.system.model.Educationtype;
import cn.stylefeng.guns.modular.system.model.Medicaltype;
import cn.stylefeng.guns.modular.education.service.IEducationtypeService;

/**
 * 教育期刊控制器
 *
 * @author fengshuonan
 * @Date 2020-06-21 00:15:02
 */
@Controller
@RequestMapping("/educationtype")
public class EducationtypeController extends BaseController {

    private String PREFIX = "/education/educationtype/";

    @Autowired
    private IEducationtypeService educationtypeService;

    /**
     * 跳转到教育期刊首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "educationtype.html";
    }

    /**
     * 跳转到添加教育期刊
     */
    @RequestMapping("/educationtype_add")
    public String educationtypeAdd() {
        return PREFIX + "educationtype_add.html";
    }

    /**
     * 跳转到修改教育期刊
     */
    @RequestMapping("/educationtype_update/{educationtypeId}")
    public String educationtypeUpdate(@PathVariable Integer educationtypeId, Model model) {
        Educationtype educationtype = educationtypeService.selectById(educationtypeId);
        model.addAttribute("item",educationtype);
        LogObjectHolder.me().set(educationtype);
        return PREFIX + "educationtype_edit.html";
    }

    /**
     * 获取教育期刊列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
    	EntityWrapper<Educationtype> wrapper = new EntityWrapper<Educationtype>();
    	wrapper.like("goods_name", condition).or()
    	.like("id", condition);
        return educationtypeService.selectList(wrapper);
    }

    /**
     * 新增教育期刊
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Educationtype educationtype) {
        educationtypeService.insert(educationtype);
        return SUCCESS_TIP;
    }

    /**
     * 删除教育期刊
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer educationtypeId) {
        educationtypeService.deleteById(educationtypeId);
        return SUCCESS_TIP;
    }

    /**
     * 修改教育期刊
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Educationtype educationtype) {
        educationtypeService.updateById(educationtype);
        return SUCCESS_TIP;
    }

    /**
     * 教育期刊详情
     */
    @RequestMapping(value = "/detail/{educationtypeId}")
    @ResponseBody
    public Object detail(@PathVariable("educationtypeId") Integer educationtypeId) {
        return educationtypeService.selectById(educationtypeId);
    }
    @InitBinder
   	public void initBinder(WebDataBinder binder) {
   	    DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
   	    binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true));        
   	}
}
